package com.hnyfkj.jyindustry.biz.raspi.controller;


import com.hnyfkj.jyindustry.biz.raspi.dto.RaspiInsertDto;
import com.hnyfkj.jyindustry.biz.raspi.dto.RaspiQueryDto;
import com.hnyfkj.jyindustry.biz.raspi.dto.RaspiUpdateDto;
import com.hnyfkj.jyindustry.biz.raspi.entity.Raspi;
import com.hnyfkj.jyindustry.biz.raspi.service.RaspiService;
import com.hnyfkj.jyindustry.biz.raspi.vo.RaspiVo;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import com.hnyfkj.jyindustry.common.dto.RespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author zhangzhang
 * @email 15838129129@163.com
 * @date 2021-04-18 16:08:50
 */
@Controller
@RequestMapping("raspi")
public class RaspiController {
    @Autowired
    private RaspiService raspiService;

    /**
     * 列表页面
     */
    @GetMapping("/listPage")
    public String listPage() {
        return "raspi/raspi-table";
    }

    /**
     * 添加页面
     */
    @GetMapping("/add")
    public String addPage() {
        return "raspi/raspi-add";
    }

    /**
     * 编辑页面
     */
    @GetMapping("/edit")
    public String editPage(@RequestParam("id") String id, Model model) {
        Raspi piScreen = raspiService.getById(id);
        System.out.println(piScreen);
        model.addAttribute("pi", piScreen);
        return "raspi/raspi-edit";
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public RespDto<PageReturnDto<RaspiVo>> list(@RequestBody RaspiQueryDto queryDto) {
        return RespDto.succResult(raspiService.queryPage(queryDto));
    }


    /**
     * 列表无分页
     */
    @RequestMapping("/listNoPage")
    @ResponseBody
    public RespDto<List<Raspi>> listNoPage() {
        return RespDto.succResult(raspiService.list());
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public RespDto<Raspi> info(@PathVariable("id") Integer id) {
        Raspi piScreen = raspiService.getById(id);
        return RespDto.succResult(piScreen);
    }

    /**
     * 保存
     */
    @RequestMapping("/insert")
    @ResponseBody
    public RespDto<String> insert(@RequestBody RaspiInsertDto RaspiInsertDto) {
        raspiService.insert(RaspiInsertDto);
        return RespDto.succ();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public RespDto<String> update(@RequestBody RaspiUpdateDto userupdateDto) {
        raspiService.update(userupdateDto);
        return RespDto.succ();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ResponseBody
    public RespDto<String> delete(String ids) {
        System.out.println(ids);
        raspiService.delete(ids);
        return RespDto.succ();
    }


}
